<?php
    define('DATABASE','dealscombined');
	require '/var/www/sandbox/dealscombined.co.uk/scripts/connect.php';
	$file = "categories.json";
		
	// Select DB
	$db=mysql_select_db(DATABASE,$connect);
	if(!$db) {
		die('Can\'t use DATABASE : '.mysql_error());
	}
	
	$unmappedProducts = array();
	mysql_query("TRUNCATE TABLE unmapped_products");
	$result = mysql_query("SELECT * FROM products WHERE mapped_category IS NULL");
	
	while($row = mysql_fetch_assoc($result)){
		
		$unmappedProducts[$row['id']] = 
		html_entity_decode($row['product_name']).
		' '.html_entity_decode($row['description']).
		' '.html_entity_decode($row['category_name']).
		' '.html_entity_decode($row['merchant_category']).
		' '.html_entity_decode($row['brand_name']).
		' '.html_entity_decode($row['description']).
		' '.html_entity_decode($row['promotional_text']).
		' '.html_entity_decode($row['specifications']);
	}
	
	foreach($unmappedProducts as $key => $value){
		mysql_query("INSERT INTO unmapped_products SET product_id =".$key.", title ='".mysql_real_escape_string($value)."'");
	}
?>